window.onload = function () {

    //面板显示
    showbord();
    //面板隐藏
    hidebord();
    //面板切换
    changebord();


    console.log(33);

    const ousername = document.getElementById('#username');
    const opwd = document.getElementById('#pwd');
    const submit = document.getElementById('#submit');
    const ologin1middleleft = document.querySelector('.login-qq-pwd');
    console.log(ologin1middleleft)
    //if (!(ologin1middleleft.contains('none'))) {

        //submit.onclick = function () {
            let valuename = ousername.value;
            let valuepwd = opwd.value;
            this.getpwdlogin(valuename,valuepwd );
            getemaillogin(valuename,valuepwd);
       // }


        geterweima();

    //}
}

//面板显示和关闭
function showbord() {

    const ologin = document.querySelector('.login');

    const omask = document.querySelector('.mask');
    ologin.addEventListener('click',function (e){
        e.preventDefault();
        omask.classList.remove('none');
    })

}


function  hidebord(){
    const omask = document.querySelector('.mask');
    const oclose=document.querySelector('.close');

        oclose.addEventListener('click',function (e){
            omask.classList.add('none');
        })


}



//面板切换
 function  changebord(){


     const oLoginBtn=document.querySelectorAll('.login-btn');
     const ologinboard=document.querySelectorAll('.login-board');

     oLoginBtn.forEach(function (item,index){
         item.onclick=function (){
             for(let i=0;i<oLoginBtn.length;i++){
                 oLoginBtn[i].classList.remove('active');
                 ologinboard[i].classList.add('none')
             }
             item.classList.add('active');
             ologinboard[index].classList.remove('none')
         }
     })

     /**
      * qq登录中的密码登录
      */

     const ologinpwd=document.querySelector('.pwdbtn');
     const ologin1middleleft=document.querySelector('.login-qq-pwd');
     const ologiner=document.querySelector('.login-er')
     ologinpwd.onclick=function (){
         ologin1middleleft.classList.remove("none");
         ologiner.classList.add('none')
     }

     const ofastlogin=document.querySelector('.fast-login');
     const ologin1qqcontent=document.querySelector('.login1-qq-content');
     ofastlogin.onclick=function (){
         ologin1middleleft.classList.add('none');
         ologiner.classList.remove('none')
         // ologin1qqcontent.classList.remove('none');

     }
 }


//手机登录
function getpwdlogin(valuename, valuepwd) {
    //获取输入邮箱和密码的值
    $ajax({
        method: "get",
        url: phonelogin,

        headers: {
            "Content-Type": 'application/json',
        },
        data:{
            email:valuename,
            password:valuepwd,
        },
        success: function (e) {
            if (e.code === 200) {
                localStorage.setItem('token', e.data);
            }
        }

    })
}

// 读取本地存储信息
// 参数 ： 键值
// 返回 :  数据

//二维码登录
//二维码登录
function geterweima() {
    $ajax({
        url: erweimaurl,
        method: "post",
        success: function (e) {
            console.log(e);
            if (e.code === 200) {
                let result = e.data.unikey;
                console.log(result);
                localStorage.setItem('token', e.data.unikey);

                $ajax({
                    method: "post",
                    url: eweima2 + `?key=${result}`,

                    success: function (e) {

                        console.log(e);
                        const Oiframe = document.createElement('iframe');
                        const Ologin1 = document.querySelector('.login1-middle-left-qrcode');
                        const QRimg = document.querySelector('.img-ewm');
                        console.log(Oiframe, Ologin1, QRimg);
                        Oiframe.src = `https://music.163.com/login?codekey=${result}`;
                        Ologin1.append(Oiframe);
                        QRimg.remove();
                        if (e.code === 200) {


                            $ajax({
                                url: ewmcheck + `?key=${result}`,
                                method: "post",
                                success: function (e) {
                                    console.log(e);//等待扫码
                                    if (e.code === 800) {

                                    }

                                }
                            })
                        }


                    }

                })


            }
        }
    })
}

//邮箱登录
function getemaillogin(valuename, valuepwd) {


}















